<?php
include_once 'MySQLDAO.php';

/**
 * Definition of Class Roombookings
 * This class represents a data access object for the database table 'roombookings'.
 */
class Roombookings {


	public $dao = null;

	private $i = 1;

	/**
	 * associated database field: hotelId, type: int, is nullable: false
	 */
	private $hotelId  = 0;

	/**
	 * associated database field: bookingId, type: int, is nullable: false
	 */
	private $bookingId  = 0;

	/**
	 * associated database field: roomId, type: int, is nullable: false
	 */
	private $roomId  = 0;

	/**
	 * associated database field: numGuests, type: int, is nullable: true
	 */
	private $numGuests;

	private $hotels = null;

	private $bookings = null;

	private $rooms = null;



	/**
	 * Default constructor
	 * @param value some value
	 */
	function __construct(){
		$this->dao = new MySQLDao("RoomBookings");
	}


	/**
	 * Initialize the business object with data read from the DB.
	 * @param row database row array containing the values from one read record
	 */
	public function init($row){
		if(isset($row['hotelId'])) $this->hotelId = $row['hotelId'];
		if(isset($row['bookingId'])) $this->bookingId = $row['bookingId'];
		if(isset($row['roomId'])) $this->roomId = $row['roomId'];
		if(isset($row['numGuests'])) $this->numGuests = $row['numGuests'];
	}


	/**
	 * Returns the string representation for this object
	 * @param escapeQuotationMarks boolean value to indicate if quotation marks in value strings should be escaped, default value is true
	 * @return String String representation of Roombookings
	 */
	public function toString($escapeQuotationMarks=true){
		$s = '[';
		$s .= 'hotelId: '.(($escapeQuotationMarks===true) ? addslashes($this->hotelId) : $this->hotelId).', ';
		$s .= 'bookingId: '.(($escapeQuotationMarks===true) ? addslashes($this->bookingId) : $this->bookingId).', ';
		$s .= 'roomId: '.(($escapeQuotationMarks===true) ? addslashes($this->roomId) : $this->roomId).', ';
		$s .= 'numGuests: '.(($escapeQuotationMarks===true) ? addslashes($this->numGuests) : $this->numGuests);
		$s .= ']';
		return $s;
	}


	/**
	 * Returns the JSON (JavaScript Object Notation) string representation for this object
	 * @return String JSON representation of Roombookings
	 */
	public function toJSONString(){
		$fieldValues = array ("hotelId"=>$this->hotelId, "bookingId"=>$this->bookingId, "roomId"=>$this->roomId, "numGuests"=>$this->numGuests);
		return json_encode($fieldValues);
	}


	/**
	 * Returns a HTML representation of this object using DIVs for formatting via css
	 * @param escapeHTML boolean value to indicate if value strings should be html escaped, default value is true
	 * @return String the HTML representation of the Roombookings object
	 */
	public function toHTMLString($escapeHTML=true){
		$htmlCode = "<div class=\"roombookings\">\n";
		$htmlCode .= '	<div class="roombookings_hotelId">'.(($escapeHTML===true) ? htmlspecialchars($this->hotelId) : $this->hotelId)."</div>\n";
		$htmlCode .= '	<div class="roombookings_bookingId">'.(($escapeHTML===true) ? htmlspecialchars($this->bookingId) : $this->bookingId)."</div>\n";
		$htmlCode .= '	<div class="roombookings_roomId">'.(($escapeHTML===true) ? htmlspecialchars($this->roomId) : $this->roomId)."</div>\n";
		$htmlCode .= '	<div class="roombookings_numGuests">'.(($escapeHTML===true) ? htmlspecialchars($this->numGuests) : $this->numGuests)."</div>\n";
		$htmlCode .= "</div>\n";
		return $htmlCode;
	}
	/*
	public function getData($where) {
		$rows = $this->dao->getData($where);
		return $rows;
	}*/
	
	public static function deleteRecords($where) {
		$roombookings = new Roombookings();
		$roombookings->dao->deleteRecord ($where);
		return;
	}


	public static function loadAll(){
		$roombookings = new Roombookings();
		$rows = $roombookings->dao->getData("");
		$roombookingss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roombookings();
			$d->init($rows[$index]);
			array_push($roombookingss,$d);
		}
		return $roombookingss;
	}


	/**
	 * Load the Roombookings uniquely by its primary key.
	 * @param hotelId the primary key
	 * @param roomId the primary key
	 * @param bookingId the primary key
	 * @return Roombookings Instance of {@link Roombookings}
	 */
	public static function loadUnique($hotelId, $bookingId, $roomId){
		$roombookings = new Roombookings();
		$rows = $roombookings->dao->getData("`hotelId`='$hotelId' AND `bookingId`='$bookingId' AND `roomId`='$roomId'");
		$roombookings->init($rows[0]);
		return $roombookings;
	}


	/**
	 * Load all records of Roombookings uniquely by its foreign keys:
	 * roomId, hotelId
	 * @param roomId foreign key
	 * @param hotelId foreign key
	 * @return array of Instance of {@link Roombookings}
	 */
	public static function loadByFKRoomidHotelid($roomId, $hotelId){
		$roombookings = new Roombookings();
		$rows = $roombookings->dao->getData("`roomId`='$roomId' AND `hotelId`='$hotelId'");
		$roombookingss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roombookings();
			$d->init($rows[$index]);
			array_push($roombookingss,$d);
		}
		return $roombookingss;
	}


	/**
	 * Load all records of Roombookings uniquely by its foreign keys:
	 * hotelId
	 * @param hotelId foreign key
	 * @return array of Instance of {@link Roombookings}
	 */
	public static function loadByFKHotelid($hotelId){
		$roombookings = new Roombookings();
		$rows = $roombookings->dao->getData("`hotelId`='$hotelId'");
		$roombookingss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roombookings();
			$d->init($rows[$index]);
			array_push($roombookingss,$d);
		}
		return $roombookingss;
	}


	/**
	 * Load all records of Roombookings uniquely by its foreign keys:
	 * bookingId
	 * @param bookingId foreign key
	 * @return array of Instance of {@link Roombookings}
	 */
	public static function loadByFKBookingid($bookingId){
		$roombookings = new Roombookings();
		$rows = $roombookings->dao->getData("`bookingId`='$bookingId'");
		$roombookingss = array();
		for ($index = 0; $index < sizeof($rows); $index++) {
			$d = new Roombookings();
			$d->init($rows[$index]);
			array_push($roombookingss,$d);
		}
		return $roombookingss;
	}


	/**
	 * Insert this object into the DB
	 * @return number new id (auto increment value) genereated
	 */
	public function insert(){
		$list = array("hotelId"=>$this->hotelId, "bookingId"=>$this->bookingId, "roomId"=>$this->roomId, "numGuests"=>$this->numGuests);
		return $this->dao->insertRecord($list);
	}


	/**
	 * Update this object into the DB
	 * @return number the number of updated records
	 */
	public function update(){
		$list = array("hotelId"=>$this->hotelId, "bookingId"=>$this->bookingId, "roomId"=>$this->roomId, "numGuests"=>$this->numGuests);
		$where = "`hotelId`='$hotelId' AND `bookingId`='$bookingId' AND `roomId`='$roomId'";
		return $this->dao->updateRecord($list,$where);
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initPOST(){
		if (isset($_POST['hotelId'])){
			$this->hotelId = $_POST['hotelId'];
		}
		if (isset($_POST['bookingId'])){
			$this->bookingId = $_POST['bookingId'];
		}
		if (isset($_POST['roomId'])){
			$this->roomId = $_POST['roomId'];
		}
		if (isset($_POST['numGuests'])){
			$this->numGuests = $_POST['numGuests'];
		}
	}


	/**
	 * Initialize the business object with data read from the DB.
	 */
	public function initGET(){
		if (isset($_GET['hotelId'])){
			$this->hotelId = $_GET['hotelId'];
		}
		if (isset($_GET['bookingId'])){
			$this->bookingId = $_GET['bookingId'];
		}
		if (isset($_GET['roomId'])){
			$this->roomId = $_GET['roomId'];
		}
		if (isset($_GET['numGuests'])){
			$this->numGuests = $_GET['numGuests'];
		}
	}


	/**
	 * Returns the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getHotelId(){
		return $this->hotelId;
	}


	/**
	 * Set the value from the database field hotelId.
	 * In the database the field hotelId is of type int.
	 * The database field is NOT nullable.
	 * @param hotelId String with the value for the field to be set
	 */
	public function setHotelId($hotelId){
		$this->hotelId = $hotelId;
	}


	/**
	 * Returns the value from the database field bookingId.
	 * In the database the field bookingId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getBookingId(){
		return $this->bookingId;
	}


	/**
	 * Set the value from the database field bookingId.
	 * In the database the field bookingId is of type int.
	 * The database field is NOT nullable.
	 * @param bookingId String with the value for the field to be set
	 */
	public function setBookingId($bookingId){
		$this->bookingId = $bookingId;
	}


	/**
	 * Returns the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @return String the value of the field
	 */
	public function getRoomId(){
		return $this->roomId;
	}


	/**
	 * Set the value from the database field roomId.
	 * In the database the field roomId is of type int.
	 * The database field is NOT nullable.
	 * @param roomId String with the value for the field to be set
	 */
	public function setRoomId($roomId){
		$this->roomId = $roomId;
	}


	/**
	 * Returns the value from the database field numGuests.
	 * In the database the field numGuests is of type int.
	 * The database field is  nullable.
	 * @return String the value of the field
	 */
	public function getNumGuests(){
		return $this->numGuests;
	}


	/**
	 * Set the value from the database field numGuests.
	 * In the database the field numGuests is of type int.
	 * The database field is  nullable.
	 * @param numGuests String with the value for the field to be set
	 */
	public function setNumGuests($numGuests){
		$this->numGuests = $numGuests;
	}


	/**
	 * Returns an instance of the linked Hotels object.
	 * A One to Many (1:n) relation exists between the Roombookings and the Hotels table.
	 * @return Hotels the linked instance of Hotels
	 */
	public function getHotels(){
		if($this->hotels == null){
			$this->hotels = Hotels::loadUnique($this->hotelId);
		}
		return $this->hotels;
	}


	/**
	 * Set a link to a related Hotels instance
	 * @param targetObjectInstanceName instance of Hotels to be linked to this object instance
	 */
	public function setHotels($hotels){
		$hotels->hotelId = $this->hotelId;
		$this->hotels = $hotels;
	}


	/**
	 * Returns an instance of the linked Bookings object.
	 * A One to Many (1:n) relation exists between the Roombookings and the Bookings table.
	 * @return Bookings the linked instance of Bookings
	 */
	public function getBookings(){
		if($this->bookings == null){
			$this->bookings = Bookings::loadUnique($this->bookingId);
		}
		return $this->bookings;
	}


	/**
	 * Set a link to a related Bookings instance
	 * @param targetObjectInstanceName instance of Bookings to be linked to this object instance
	 */
	public function setBookings($bookings){
		$bookings->bookingId = $this->bookingId;
		$this->bookings = $bookings;
	}


	/**
	 * Returns an instance of the linked Rooms object.
	 * A One to Many (1:n) relation exists between the Roombookings and the Rooms table.
	 * @return Rooms the linked instance of Rooms
	 */
	public function getRooms(){
		if($this->rooms == null){
			$this->rooms = Rooms::loadUnique($this->roomId, $this->hotelId);
		}
		return $this->rooms;
	}


	/**
	 * Set a link to a related Rooms instance
	 * @param targetObjectInstanceName instance of Rooms to be linked to this object instance
	 */
	public function setRooms($rooms){
		$rooms->roomId = $this->roomId;
		$this->rooms = $rooms;
	}
}
?>